/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package datasource;

import java.io.Serializable;

/**
 *
 * @author minaev
 */
public class SlideFilter implements Serializable {
    int filter_value;
    double vals[];
    double resval = 0;
    int cur_val = 0;
    

    public SlideFilter(int filter_value) {
        this.filter_value = filter_value;
        vals = new double[filter_value];
    }
    
    public void initFilter(double initValue){
        for (int i = 0; i < filter_value; i++) {
            vals[i] = initValue;
            resval = initValue;
        }
    }
    
    public double filter(double nval){
        vals[cur_val] = nval;
        if(++cur_val >= filter_value){
            cur_val = 0;
        }
        resval += nval/filter_value;
        resval -= vals[cur_val]/filter_value;
        return resval;
    }
    
}
